jQuery(function($){
	jQuery("#datagrid").jqGrid({
	    url:'listRole.action',  
	    mtype: "POST",
	    datatype: "json",
	    colNames:['角色名称', '角色描述', '创建日期', '修改日期'],
	    colModel:[
            {name:'role_name',index:'role_name',align:'center'},
	        {name:'description',index:'description'},
	        {name:'create_time',index:'create_time',datefmt:'Y-m-d',width:100},
	        {name:'modify_time',index:'modify_time',datefmt:'Y-m-d',width:100}	
	    ],
	    jsonReader: {
	    	root: "results",
	    	total: "totalpages",
	    	page: "currpage",
	    	records: "totalrecords",
	    	repeatitems: false
	    },
	    pager: '#pager',
	    rowNum:10,
	    rowList:[10,20,30],
	    sortname: 'role_id',
	    multiselect: true,
	    viewrecords: true,
	    sortorder: "ASC",
	    caption: "角色列表",
	    autowidth: true,
	    height: '100%',
	    ondblClickRow: function(id, ri, ci, e){
	    	loadRole(id);
	    }
	});
	
	jQuery("#datagrid").navGrid(
		'#page',
		{add:false, edit:false, del:true, search:false, refresh:true},
		{},{},
		{
			modal:true,url:"deleteRole.action",
			afterSubmit:function(data, params){
				if(data.responseText) {
					var obj = eval('('+ data.responseText +')');
					var msg = obj.message?obj.message:((obj.success==true || obj.success=='true')?"角色信息删除成功！":"角色信息删除失败！");
					return [obj.success, msg];
				} else {
					return [true];
				}
			}
		},{},{}
	);
});

function loadRole(role_id) {
	showMDialog('loadRole.action?edit=true&role.role_id='+role_id,'dialogWidth=900px;dialogHeight=600px');
//	window.open('loadRole.action?edit=true&role.role_id='+role_id);
}

function configRole() {
//	var selectedId = $("#manager_list").jqGrid("getGridParam", "selrow");
//	var rowData = $("#manager_list").jqGrid("getRowData", selectedId);
//	var selectedIds = $("#manager_list").jqGrid("getGridParam", "selarrrow");
	
	var selectedId = $("#datagrid").jqGrid("getGridParam", "selrow");
	if(selectedId) {
		showMDialog('loadConfigRole.action?system.valid_flag=1&role.role_id='+selectedId,'dialogWidth=900px;dialogHeight=600px');
//		window.open('loadConfigRole.action?system.valid_flag=1&role.role_id='+selectedId);
	}
	
//	showMDialog('loadRole.action?edit=true&role.role_id='+role_id,'dialogWidth=900px;dialogHeight=600px');
}

function gridReload(){
	jQuery("#datagrid").trigger("reloadGrid");
}